//
//  TopViewController.m
//  MyMovie
//
//  Created by apple on 16/5/10.
//  Copyright © 2016年 ljp. All rights reserved.
//

#import "TopViewController.h"
#import "StarView.h"
#import "TopCell.h"
#import "Top250DatailViewController.h"



@interface TopViewController ()<UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
{
    NSMutableArray *topArray;
    NSMutableArray *commentArray;
}
@end

@implementation TopViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self loadData];


}

-(void)loadData {

    NSDictionary *dic = [JSONDataService loadJSONFielWithName:@"top250"];

    topArray = [[NSMutableArray alloc] init];

    for (NSDictionary*d in dic[@"subjects"]) {

        Top *top = [[Top alloc]initWithDictionary:d];

        [topArray addObject:top];
    }

}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {

    return topArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {


    TopCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TopCell" forIndexPath:indexPath];
    cell.top = topArray[indexPath.item];


    return cell;
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {

    CGFloat cellwidth = (KScreenWidth - 40) / 3 - 0.1;
    return CGSizeMake(cellwidth, cellwidth*1.4);
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {

    Top250DatailViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"Top250DatailViewController"];
    [self.navigationController pushViewController:vc animated:YES];

    

}







@end
